package com.iceberg.adgt.ui.architecture;

import com.iceberg.adgt.domain.LayerDTO;

import javax.swing.*;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * @author David
 */
public final class LayerListModel extends AbstractListModel {

	private final List<LayerDTO> layers = new LinkedList<LayerDTO>();

	public LayerListModel() {

	}

	public LayerListModel(Map<String, LayerDTO> layersMap) {
		layers.addAll(layersMap.values());
	}

	@Override
	public int getSize() {
		return layers.size();
	}

	@Override
	public String getElementAt(int index) {
		return layers.get(index).getNumber() + ": " + layers.get(index).getName();
	}

	public String getLayerAt(int index) {
		return layers.get(index).getName();
	}

	public int getIndexOfLayer(String layer) {
		if (layer != null) {
			for (LayerDTO layerInList : layers) {
				if (layerInList.getName().equals(layer)) {
					return layers.indexOf(layerInList);
				}
			}
		}
		return -1;
	}
}
